﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.DAL;
using MINERP.DAL.PrintManage;
using MINERP.MODEL.FoundationModel;
using MINERP.MODEL.PrintManage;


namespace MINERP.BLL.PrintManage
{
    public  class FrontierBLL
    {
        public List<OrderFileModel> GetOrderFileList(int printerId,int status)
        {
            List<OrderFileModel> list = new List<OrderFileModel>();
            using (newSampleYPDBEntities entity = new newSampleYPDBEntities())
            {
                List<OrderFile> listOrderFile;
                if(status ==0)
                {
                    listOrderFile = entity.OrderFile.Where(o => o.printer.PrinterID == printerId).OrderBy(o=>o.createTime).ThenByDescending(o=>o.Priority).ToList();
                }
                else
                {
                    listOrderFile = entity.OrderFile.Where(o => o.printer.PrinterID == printerId && o.Status == status).OrderBy(o => o.createTime).ThenByDescending(o => o.Priority).ToList();
                }
                foreach (var item in listOrderFile)
                {
                    OrderFileModel om = new OrderFileModel();
                    om.ConditionFilePath = item.ConditionFilePath;
                    om.CreateTime = item.createTime;
                    om.FolderName = item.FolderName;
                    om.lastPrintTime = item.lastPrintTime;
                    om.OrderFileID = item.OrderFileID;
                    if(!item.orderInfoReference.IsLoaded)
                    {
                        item.orderInfoReference.Load();
                    }
                    om.OrderProductId = item.orderInfo.OrderProductId;
                    if(!item.paperFaceReference.IsLoaded)
                    {
                        item.paperFaceReference.Load();
                    }
                    om.PaperFaceId = item.paperFace.PaperFaceID;
                    om.PaperFaceName = item.paperFace.Name;
                    if (!item.paperTypeReference.IsLoaded)
                    {
                        item.paperTypeReference.Load();
                    }
                    om.PaperTypeId = item.paperType.PaperTypeID;
                    om.PaperTypeName = item.paperType.Name;
                    if(!item.printerReference.IsLoaded)
                    {
                        item.printerReference.Load();
                    }
                    om.PrinterId = item.printer.PrinterID;
                    om.Priority = item.Priority;
                    om.Remark = item.Remark;
                    om.Status = item.Status;
                    switch (item.Status)
                    {
                        case 0:
                            om.StatusName = "未打印";
                            break;
                        case 1:
                            om.StatusName = "正在打印";
                            break;
                        case 2:
                            om.StatusName = "打印完成";
                            break;
                        default:
                            break;
                    }
                    list.Add(om);

                }
            }
            return list;
        }
    }
}
